package com.anjho.pojo;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "neighborhood")
@NamedQueries(value = {
		@NamedQuery(name = "Neighborhood.getNeighborhoodList", query = "SELECT n FROM Neighborhood n"),
		@NamedQuery(name = "Neighborhood.getNeighborhoodByNhcode", query = "SELECT n FROM Neighborhood n WHERE n.nhcode = :nhcode")
})
public class Neighborhood implements Serializable {
	
	private static final long serialVersionUID = -6548967225000019436L;
	
	public Neighborhood() {
		this.setName("");
		this.setCity(new City());
	}
	
	@Id
	@Column(name="nhcode")
	@OneToMany(mappedBy="neighborhood")
	private int nhcode;
	
	@ManyToOne
	@JoinColumn(name="cicode", nullable=false)
	private City city;
	
	@Column(name="name", nullable=false, length=72)
	private String name;

	public int getNhcode() {
		return nhcode;
	}

	public void setNhcode(int nhcode) {
		this.nhcode = nhcode;
	}

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + nhcode;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Neighborhood other = (Neighborhood) obj;
		if (nhcode != other.nhcode)
			return false;
		return true;
	}
}
